package platform.logging;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;


public class LogContext {
	
	public static void debug(Logger log,Object... message) {
		log.debug(format(" - ","0",message));
	}
	
	public static void info(Logger log,Object... message) {
		log.info(format(" - ","0",message));
	}
	
	public static String format(String separator, String replaceValue, Object... objects) {
		List<Object> objs = new ArrayList<Object>();
		if (objects != null && objects.length > 0) {

			for (Object object : objects) {
				objs.add(object);
			}
			String result = format(separator, replaceValue, objs);
			objs.clear();
			objs = null;

			return result;
		} else {
			return null;
		}
	}
	/**
	 * 将参数列表使用separator连接起来，如果参数列表中的某个参数为空，则使用replaceValue代替
	 * 
	 * @param separator
	 *            连接符
	 * @param replaceValue
	 *            如果参数列表中的某个参数为空，则使用replaceValue代替
	 * @param objects
	 *            List参数列表
	 * @return
	 */
	public static String format(String separator, String replaceValue, List<Object> objects) {
		StringBuffer info = new StringBuffer();
		for (Object object : objects) {
			if (object != null && !object.toString().isEmpty()) {
				info.append(object.toString()).append(separator);
			} else {
				info.append(replaceValue).append(separator);
			}
		}
		return info.substring(0, info.length() - separator.length());
	}
}
